﻿#include "Hashbucket.h"

namespace Ysz
{
	
	template<class K,class V>
	struct mapKeyOfT
	{
		const K& operator()(const pair<const K, V>& data)
		{
			return data.first;
		}

	};


	template<class K, class V, class KeyOfT = mapKeyOfT<K,V>, class Hash = Hash<K >>
	class unordered_map
	{
		
	

		typedef typename HashTable<K, pair<const K,V>, KeyOfT, Hash>::iterator iterator;
		typedef typename HashTable<K, pair<const K,V>, KeyOfT, Hash>::const_iterator const_iterator;
	public:

		iterator begin()
		{
			return _hashtable.begin();
		}

		iterator end()
		{
			return _hashtable.end();
		}


		const_iterator begin() const
		{
			return _hashtable.begin();
		}

		const_iterator end() const
		{
			return _hashtable.end();
		}



		pair<iterator, bool> insert(const pair<const K, V>& data)
		{

			return _hashtable.insert(data);
		}

		iterator find(const K& key)
		{
			return _hashtable.find(key);
		}

		iterator erase(const K& key)
		{
			return _hashtable.erase(key);
		}
		size_t size()const { return _hashtable.size(); }//数据个数
		bool empty()const { return _hashtable.empty(); }//表是否为空

		size_t bucket_count() { return _hashtable.BucketCount(); }//哈希桶的个数
		size_t bucket_size(const K& key) { return _hashtable.BucketSize(key); }//根据key查找属于哪个哈希桶

		size_t count(const K& key)//查找元素有返回1无返回0
		{
			return _hashtable.find(key) != end();
		}
		V& operator[](const K& key)
		{
		
			auto it = insert({ key ,V() }).first;
			return it->second;
		}
	private:
		HashTable<K, pair<const K, V>, KeyOfT, Hash> _hashtable;
	};

}